<?php
$config = new RM_Config();
$currencySymbol = $config->getValue('rm_config_currency_symbol');

$priceConfigModel = new RM_UnitDailyPricesConfig();
$weekendPriceEnabled = (int)$priceConfigModel->fetchValueByUnit($this->unit->id, 'weekend_price_enabled');
$dailyPriceEnabled = (int)$priceConfigModel->fetchValueByUnit($this->unit->id, 'daily_price_enabled');
$midweekDays = explode(",",$priceConfigModel->fetchValueByUnit($this->unit->id, 'midweek_days'));
$weekendDays = explode(",",$priceConfigModel->fetchValueByUnit($this->unit->id, 'weekend_days'));
$monthlyPriceEnabled = (int)$priceConfigModel->fetchValueByUnit($this->unit->id, 'monthly_price_enabled');

$dayArray = str_replace("'", '"', $this->_translate->_('Common.JSON','WeekDaysShort'));
$dayArray = Zend_Json::decode($dayArray);

foreach ($midweekDays as $midweekDay){
    if (isset($midweekDay) && $midweekDay!=="") {
        $midweekDaysArray[] = $dayArray[$midweekDay];
    }
}
if (isset($midweekDaysArray)){
    $midweekDaysText = implode(",", $midweekDaysArray);
}

foreach ($weekendDays as $weekendDay){
    $weekendDaysArray[] = $dayArray[$weekendDay];
}
$weekendDaysText = implode(",", $weekendDaysArray);


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" dir="ltr" id="RM_price_module_pricelist_page" >
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    </head>
    <body>
        <link rel="stylesheet" type="text/css" href="<?php echo RM_Environment::getConnector()->getRootURL(); ?>RM/userdata/css/user.css"/>
        <link rel="stylesheet" type="text/css" href="<?php echo RM_Environment::getConnector()->getRootURL(); ?>RM/userdata/css/user_overrides.css"/>
        <div class="RM_price_module_pricelist_container">
            <div class="RM_price_module_pricelist_header_container">
                <div class="RM_price_module_pricelist_header">
                    <?php echo $this->unit->name."&nbsp;".$this->_translate->_('User.Unit.Prices','Title');?>
                </div>
            </div>
            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="RM_divTable">
              <tr class="RM_divHeaderRow">
                <td class="RM_divHead">
                    <?php echo $this->_translate->_('User.Unit.List','PeriodName');?>
                </td>
                <td class="RM_divHead">
                    <?php echo $this->_translate->_('User.Unit.List','StartDate');?>
                </td>
                <td class="RM_divHead">
                    <?php echo $this->_translate->_('User.Unit.List','EndDate');?>
                </td>
                <td class="RM_divHead">
                    <?php echo $this->_translate->_('User.Unit.List','MinStay');?>
                </td>
                <td class="RM_divHead">
                    <?php echo $this->_translate->_('User.Unit.List','MaxStay');?>
                </td>
                <?php if (!empty($midweekDays) && isset($midweekDaysText)) { ?>
                    <td class="RM_divHead">
                        <?php echo $this->_translate->_('User.Unit.List','MidWeekPrice');?><br/>
                        <?php echo $midweekDaysText;?>
                    </td>
                <?php } ?>
                <?php if ($dailyPriceEnabled === 1) { ?>
                    <td class="RM_divHead">
                        <?php echo $this->_translate->_('User.Unit.List','WeekdayPrice');?>
                    </td>
                <?php } ?>
                <?php if ($weekendPriceEnabled === 1) { ?>
                    <td class="RM_divHead">
                        <?php echo $this->_translate->_('User.Unit.List','WeekendPrice');?><br/>
                        <?php echo $weekendDaysText;?>
                    </td>
                <?php } ?>
                <td class="RM_divHead">
                    <?php echo $this->_translate->_('User.Unit.List','WeeklyPrice');?>
                </td>
                <?php if ($monthlyPriceEnabled === 1) { ?>
                    <td class="RM_divHead">
                        <?php echo $this->_translate->_('User.Unit.List','MonthlyPrice');?><br/>
                    </td>
                <?php } ?>
              </tr>
              <?php
                $config = new RM_Config();
                $dateFormat = $config->getJSDateformat();
                $prices = $this->prices;
                $i=0;
                foreach ($prices as $price) {
                    if ($i % 2 != 0) {
                        // odd rows
                        $rowStyle = "RM_list_row_style1";
                    } else {
                        // even rows
                        $rowStyle = "RM_list_row_style2";
                    }
                    $i++; # Increment our row counter

                    // row loop
                    ?>
                    <tr>
                        <td class="RM_divRow" class="<?php echo $rowStyle;?>">
                            <!-- period_name -->
                            <?php echo $price['period_name'];?>
                        </td>
                        <td class="RM_divRow" class="<?php echo $rowStyle;?>">
                            <!-- start_datetime -->
                            <?php echo date($dateFormat, strtotime($price['start_datetime']));?>
                        </td>
                        <td class="RM_divRow" class="<?php echo $rowStyle;?>">
                            <!-- end_datetime -->
                            <?php echo date($dateFormat, strtotime($price['end_datetime']));?>
                        </td>
                        <td class="RM_divRow" class="<?php echo $rowStyle;?>">
                            <!-- min_stay -->
                            <?php
                            if ((int)$price['min_stay']>0) {
                                echo $price['min_stay'];
                            } else {
                                echo $this->_translate->_('User.Unit.List','NoRestriction');
                            }
                            ?>
                        </td>
                        <td class="RM_divRow" class="<?php echo $rowStyle;?>">
                            <!-- max_stay -->
                            <?php
                            if ((int)$price['max_stay']>0) {
                                echo $price['max_stay'];
                            } else {
                                echo $this->_translate->_('User.Unit.List','NoRestriction');
                            }
                            ?>
                        </td>
                        <?php if (!empty($midweekDays) && isset($midweekDaysText)) { ?>
                            <td class="RM_divRow" class="<?php echo $rowStyle;?>">
                                <!-- weekday_price -->
                                <?php echo $currencySymbol.$price['midweek_price'];?>
                            </td>
                        <?php } ?>
                        <?php if ($dailyPriceEnabled === 1) { ?>
                            <td class="RM_divRow" class="<?php echo $rowStyle;?>">
                                <!-- weekday_price -->
                                <?php echo $currencySymbol.$price['weekday_price'];?>
                            </td>
                        <?php } ?>
                        <?php if ($weekendPriceEnabled === 1) { ?>
                            <td class="RM_divRow" class="<?php echo $rowStyle;?>">
                                <!-- weekend_price -->
                                <?php echo $currencySymbol.$price['weekend_price'];?>
                            </td>
                        <?php } ?>
                        <td class="RM_divRow" class="<?php echo $rowStyle;?>">
                            <!-- weekly_rate -->
                            <?php echo $currencySymbol.$price['weekly_rate'];?>
                        </td>
                         <?php if ($monthlyPriceEnabled === 1) { ?>
                            <td class="RM_divRow" class="<?php echo $rowStyle;?>">
                                <!-- monthly_price -->
                                <?php echo $currencySymbol.$price['monthly_rate'];?>
                            </td>
                        <?php } ?>
                    </tr>
            <?php } // end row loop ?>
            </table>

        </div>
    </body>
</html>